﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="HotelList.aspx.cs" Inherits="FastTravel.IntranetWeb.HotelList" %>
<%@ Register Assembly="Ext.Net" Namespace="Ext.Net" TagPrefix="ext" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
	<title>Список отелей</title>
	 <ext:XScript ID="xScript" runat="server">
		<Script type="text/javascript">
			var clearFilter = function () {
				#{txtFilterHotelName}.reset();
				#{comboFilterHotelStarLevel}.reset();
				#{comboFilterHotelCountry}.reset();
				#{comboFilterHotelResort}.reset();
				#{grdHotel}.getStore().clearFilter();
			}
		</Script>
	</ext:XScript>
	<script type="text/javascript">
		
		var hotelStarLevel = function (value) {
			switch(value){
				case "0":
					return 'Нет звезд';
					break;
				case "1":
					return '1 звезда';
					break;
				case "2":
					return '2 звезды';
					break;
				case "3":
					return '3 звезды';
					break;
				case "4":
					return '4 звезды';
					break;
				case "5":
					return '5 звезд';
					break;
		};

	</script>
</head>
<body>
	<form id="formHotelList" runat="server">
	<ext:ResourceManager ID="resourceManager" runat="server" Theme="Gray" DirectMethodNamespace="FastTravel.IntranetWeb"/>

	<!-- resort storage -->
	<%--<ext:Store runat="server" ID="ResortStore" AutoLoad="false" OnRefreshData="ResortRefresh">
		<DirectEventConfig>
			<EventMask ShowMask="false" />
		</DirectEventConfig>
		<Reader>
			<ext:JsonReader IDProperty="ID">
				<Fields>
					<ext:RecordField Name="ID" Type="String" Mapping="ID" />
					<ext:RecordField Name="Name" Type="String" Mapping="Name" />
				</Fields>
			</ext:JsonReader>
		</Reader>
		<Listeners>
			<Load Handler="#{comboFilterHotelResort}.setValue(#{comboFilterHotelResort}.store.getAt(0).get('ID'));" />
		</Listeners>
	</ext:Store>--%>

	<ext:GridPanel ID="grdHotel" runat="server" Title="Отели" AutoHeight="true" StripeRows="true" AutoExpandColumn="Name" TrackMouseOver="true">
			<Store>
				<ext:Store ID="StoreHotel" runat="server" OnRefreshData="StoreRefresh" RemoteSort="true">
					<Proxy>
					   <ext:PageProxy />
					</Proxy>
					<Reader>
						<ext:JsonReader IDProperty="ID" TotalProperty="total">
							<Fields>
								<ext:RecordField Name="ID" Type="Int"/>
								<ext:RecordField Name="Name" Type="String" SortDir="ASC"/>
								<ext:RecordField Name="Description" Type="String" />
								<ext:RecordField Name="CountryID" Type="Int"/>
								<ext:RecordField Name="CountryName" Type="String" />
								<ext:RecordField Name="ResortID" Type="Int" />
								<ext:RecordField Name="ResortName" Type="String" />
								<ext:RecordField Name="StarLevel" Type="Int" />
								<ext:RecordField Name="StarDescription" Type="String" />
							</Fields>
						</ext:JsonReader>
					</Reader>
					<BaseParams>
						<ext:Parameter Name="start" Value="0" Mode="Raw" />
						<ext:Parameter Name="limit" Value="10" Mode="Raw" />
						<ext:Parameter Name="sort" Value="Name" />
						<ext:Parameter Name="dir" Value="ASC" />
					</BaseParams>
					<SortInfo Field="Name" Direction="ASC" />
				</ext:Store>
			</Store>
			<ColumnModel runat="server">
				<Columns>
					<ext:Column ColumnID="ID" Header="№" Width="40" DataIndex="ID" Hidden="true"/>
					<ext:Column Header="Отель" Width="200" DataIndex="Name"/>
				<%--	<ext:Column Header="Уровень" Width="150" DataIndex="StarLevel">
						<Renderer Fn="hotelStarLevel" />
					</ext:Column>--%>
					<ext:RatingColumn Header="Рейтинг" DataIndex="StarLevel"/>
					<ext:Column Header="Страна" Width="150" DataIndex="CountryName" Sortable="false"/>
					<ext:Column Header="Курорт" Width="150" DataIndex="ResortName" Sortable="false"/>
					<ext:CommandColumn Width="55" Header="Действ.">
						<Commands>                                               
							  <ext:GridCommand CommandName="Edit" Icon="Pencil" ToolTip-Text="Изменить">                                                        
							  </ext:GridCommand>
							  <ext:GridCommand CommandName="Delete" Icon="Cross" ToolTip-Text="Удалить">
							  </ext:GridCommand>
						 </Commands>
					</ext:CommandColumn>
					
					<ext:Column Width="28" DataIndex="ID" Sortable="false" MenuDisabled="true" Header="&nbsp;" Fixed="true">
						<Renderer Handler="return '';" />
					</ext:Column>

					<ext:Column Width="28" DataIndex="ID" Sortable="false" MenuDisabled="true" Header="&nbsp;" Fixed="true">
						<Renderer Handler="return '';" />
					</ext:Column>

				</Columns>
			</ColumnModel>
			<DirectEvents>                                        
				<Command OnEvent="GridAction" Buffer="250">
					<EventMask ShowMask="true" />
						<ExtraParams>
							<ext:Parameter Name="command" Value="command" Mode="Raw"/>
							<ext:Parameter Name="id" Value="record.id" Mode="Raw"/>
						</ExtraParams>
						<Confirmation BeforeConfirm="if (command=='Edit') return false;" ConfirmRequest="true" Message="Вы хотите удалить отель?" Title="Удаление отеля" />
				</Command>
			</DirectEvents>
			<View>
				<ext:GridView ID="grdFilter" runat="server">
					<HeaderRows>
						<ext:HeaderRow>
							<Columns>
								<ext:HeaderColumn/>
								<ext:HeaderColumn>
									<Component>
										<ext:TextField runat="server" ID="txtFilterHotelName" AllowBlank="true" SelectOnFocus="true">
											<DirectEvents>
												<SpecialKey Before="return e.getKey() == Ext.EventObject.ENTER;" OnEvent="BtnSearchHotelClick"/>
											</DirectEvents>
										</ext:TextField>
									</Component>
								</ext:HeaderColumn>
								
								<ext:HeaderColumn>
									<Component>
										<ext:ComboBox runat="server" ID="comboFilterHotelStarLevel" AllowBlank="true" Width="120" Selectable="true">
										<Triggers>
											<ext:FieldTrigger Icon="Clear" HideTrigger="true" />
										</Triggers>
										 <Listeners>
											<Select Handler="this.triggers[0].show();" />
											<BeforeQuery Handler="this.triggers[0][ this.getRawValue().toString().length == 0 ? 'hide' : 'show']();" />
											<TriggerClick Handler="if (index == 0) { this.clearValue(); this.triggers[0].hide(); }" />
										</Listeners>
										<DirectEvents>
											<SpecialKey Before="return e.getKey() == Ext.EventObject.ENTER;" OnEvent="BtnSearchHotelClick"/>
										</DirectEvents>
										<Items>
											<ext:ListItem Text="Нет звезд" Value="0" />
											<ext:ListItem Text="1 звезда" Value="1" />
											<ext:ListItem Text="2 звезды" Value="2" />
											<ext:ListItem Text="3 звезды" Value="3" />
											<ext:ListItem Text="4 звезды" Value="4" />
											<ext:ListItem Text="5 звезд" Value="5" />
										</Items>
										</ext:ComboBox>
									</Component>
								</ext:HeaderColumn>
								
								<ext:HeaderColumn>
									<Component>
										<ext:ComboBox runat="server" ID="comboFilterHotelCountry" AllowBlank="true" Width="120" Selectable="true" 
										TriggerAction="All" ForceSelection="true" >
										<Triggers>
											<ext:FieldTrigger Icon="Clear" HideTrigger="true" />
										</Triggers>
										 <Listeners>
											<Select Handler="this.triggers[0].show();#{comboFilterHotelResort}.clearValue(); #{ResortStore}.reload();" />
											<BeforeQuery Handler="this.triggers[0][ this.getRawValue().toString().length == 0 ? 'hide' : 'show']();" />
											<TriggerClick Handler="if (index == 0) { this.clearValue(); this.triggers[0].hide(); }" />
										</Listeners>
											<DirectEvents>
												<SpecialKey Before="return e.getKey() == Ext.EventObject.ENTER;" OnEvent="BtnSearchHotelClick"/>
											</DirectEvents>
										</ext:ComboBox>
									</Component>
								</ext:HeaderColumn>

								<ext:HeaderColumn>
									<%--<Component>
										<ext:ComboBox runat="server" ID="comboFilterHotelResort" AllowBlank="true" Width="120" 
										Selectable="true" StoreID="ResortStore" TypeAhead="true" Mode="Local" 
										ForceSelection="true" TriggerAction="All" DisplayField="Name" ValueField="ID">
											<Triggers>
												<ext:FieldTrigger Icon="Clear" HideTrigger="true" />
											</Triggers>
											 <Listeners>
												<Select Handler="this.triggers[0].show();" />
												<BeforeQuery Handler="this.triggers[0][ this.getRawValue().toString().length == 0 ? 'hide' : 'show']();" />
												<TriggerClick Handler="if (index == 0) { this.clearValue(); this.triggers[0].hide(); }" />
											</Listeners>
											<DirectEvents>
												<SpecialKey Before="return e.getKey() == Ext.EventObject.ENTER;" OnEvent="BtnSearchHotelClick"/>
											</DirectEvents>
										</ext:ComboBox>
									</Component>--%>
								</ext:HeaderColumn>
								
								<ext:HeaderColumn/>
								
								<ext:HeaderColumn>
									<Component>
										<ext:Button runat="server" ID="btnFilterAdd" Icon="Find" >
											<ToolTips>
												<ext:ToolTip ID="tipFindData" runat="server" Html="Поиск" />
											</ToolTips>
											<DirectEvents>
												<Click OnEvent="BtnSearchHotelClick" />
											</DirectEvents>
										</ext:Button>
									</Component>
								</ext:HeaderColumn>

								<ext:HeaderColumn AutoWidthElement="false">
									<Component>
										<ext:Button ID="ClearFilterButton" runat="server" Icon="Cancel">
											<ToolTips>
												<ext:ToolTip ID="tipClearFilter" runat="server" Html="Очистить фильтр" />
											</ToolTips>
											 
											<Listeners>
												<Click Handler="clearFilter(null);" />
											</Listeners>                                            
										</ext:Button>
									</Component>
								</ext:HeaderColumn>

							</Columns>
						</ext:HeaderRow>
					</HeaderRows>
				</ext:GridView>
			</View>	
			<BottomBar>
				<ext:PagingToolbar ID="toolbarBottomPaging" runat="server" BeforePageText="Страница" AfterPageText="из" PageSize="10" DisplayInfo="true" DisplayMsg="Отели {0} - {1} из {2}      &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;" EmptyMsg="Нет отелей"  LabelAlign="Left">
					<Items>
						<ext:Label ID="lblPageSize" runat="server" Text="Размер страницы:" />
						<ext:ToolbarSpacer ID="toolbarSpacer" runat="server" Width="10"/>
						<ext:ComboBox ID="comboPageSize" runat="server" Width="50">
							<Items>
								<ext:ListItem Text="10" />
								<ext:ListItem Text="15" />
								<ext:ListItem Text="20" />
								<ext:ListItem Text="30" />
								<ext:ListItem Text="50" />
							</Items>
							<SelectedItem Value="10" />
							<Listeners>
								<Select Handler="#{toolbarBottomPaging}.pageSize = parseInt(this.getValue()); #{toolbarBottomPaging}.doLoad();" />
							</Listeners>
						</ext:ComboBox>
					</Items>
				</ext:PagingToolbar>
			</BottomBar>
			<SelectionModel>
						<ext:RowSelectionModel ID="RowSelectionModel" runat="server" SingleSelect="true">
						</ext:RowSelectionModel>
			</SelectionModel>
			<LoadMask ShowMask="true" Msg="Загрузка данных об отелях..."/>
			<SaveMask ShowMask="true" Msg="Сохранение данных об отелях..."/>
		</ext:GridPanel>

		<ext:ToolTip ID="tooltipHotel" runat="server" Target="={#{grdHotel}.getView().mainBody}" Delegate=".x-grid3-row" TrackMouse="true">
			<Listeners>
				<Show Handler="var rowIndex = #{grdHotel}.view.findRowIndex(this.triggerElement);this.body.dom.innerHTML = '<b>Описание:</b> ' + #{StoreHotel}.getAt(rowIndex).get('Description');" />
			</Listeners>
		</ext:ToolTip>  
	</form>
</body>
</html>
